﻿using System;

namespace FunctionalCLR.Core.Functions.Maths {

    /// <summary>
    /// Find the minmum value among the list
    /// </summary>
    public class MinNode : FuncNode {

        public MinNode()
            : base() {
            base.Value = "min";
        }

        public override object Evaluate() {
            double min = Double.MaxValue;
            for (int index = 0; index < Children.Count; index++) {
                double value = Convert.ToDouble(
                    Children[index].Evaluate());
                if (value < min) {
                    min = value;
                }
            }

            return min;
        }
    }
}
